home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / misc / football / exec / lstats.rexx < prev    next >
OS/2 REXX Batch file  |  1999-02-03  |  12KB  |  386 lines

  1. /* ***********************************************************************
  2.  
  3.    LEAGUE STATS PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------------
  5.                    Copyright  Mark Naughton 1996
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       211196   First release. Displays info about the league and then
  11.                     the best record/performance in the league.
  12.            211196   Steve Holland has helped immensely in improving the
  13.                     display and in what stats to display.
  14.  1.1       110497   Added code to support Points_Per_Goals.
  15.            120497   Removed code that adds Points for Goals as the
  16.                     performance options were too far out. A team with a
  17.                     246% record out of 5 matches is too much. Points Per
  18.                     Goals is now mentioned but is NOT used.
  19.            160597   Amended way the number of matches is incremented. Was
  20.                     adding an extra one.
  21.  1.2       250997   Added code for promotions and divisions.
  22.            071297   Amended Highest Home/Away win as 7-0 should be better
  23.                     than 7-2.
  24.            151297   Tidied display.
  25.            160998   Added code to give priority to teams with less goals
  26.                     scored against them. Added code to display all matches
  27.                     which match the highest home/away scores.
  28.            250199   Fixed bugs in calculating the biggest wins where if the
  29.                     match had a clean sheet, no other match could top it
  30.                     unless they had a clean sheet and scored more goals.
  31.  
  32. **************************************************************************
  33.  
  34. Procedure
  35. ---------
  36.  
  37. 1. Check files exist. Open 'Teams.df' file and read data into array/variables.
  38. 2. Open Learn file and read a line.
  39. 3. Store data on the teams that played a match (Win/Draw/Loss) for Record
  40.    and Performance.
  41. 4. Store stats for the league.
  42. 5. Calculate the biggest win/loss.
  43. 6. Format data produced for Record and Performance.
  44. 7. Display data then exit...
  45.  
  46. ************************************************************************** */
  47. PARSE ARG league_stuff
  48.  
  49. version      = 1
  50. input_file   = '.df'
  51. input2_file  = '.sflearn'
  52. title        = '*LEAGUE_NAME='
  53. points_win   = '*POINTS_PER_WIN='
  54. points_drw   = '*POINTS_PER_DRW='
  55. points_lse   = '*POINTS_PER_LSE='
  56. points_gls   = '*POINTS_PER_GLS='
  57. releg        = '*RELEGATION='
  58. playother    = '*PLAY_OTHER='
  59. promoted     = '*PROMOTED='
  60. num_divs     = '*NUM_DIVISIONS='
  61. divisions    = '*DIVISIONS='
  62. pkauthor     = '*  Author ='
  63. pkversion    = '*  Version='
  64. pkdate       = '*  Date   ='
  65. separator    = '*'
  66. not_played   = '__   __'
  67. teams.       = '???'
  68. records.     = '???'
  69. undefeat.    = '???'
  70. ustring.     = '???'
  71. rstring.     = '???'
  72. mats.        = '???'
  73. pct.         = '???'
  74. tcount       = 0
  75. lversion     = '1.0'
  76. lreg         = 2
  77. lplayo       = 2
  78. ptsgls       = 0
  79. ndivs        = 1
  80. promo        = 0
  81. divs         = ''
  82.  
  83.  
  84. parse var league_stuff league_file
  85. league_file = "Data/" || league_file
  86.  
  87. if exists(league_file || input_file) = 0  then exit
  88. if exists(league_file || input2_file) = 0 then exit
  89.  
  90. if open(datafile,league_file || input_file,'r') then do
  91.    do while ~eof(datafile)
  92.       line = readln(datafile)
  93.       if pos(title,line) > 0 then        league_title = delstr(line,1,13)
  94.       if pos(pkauthor,line) > 0 then     author       = delstr(line,1,12)
  95.       if pos(pkversion,line) > 0 then    lversion     = delstr(line,1,12)
  96.       if pos(pkdate,line) > 0 then       ddate        = delstr(line,1,12)
  97.       if pos(points_win,line) > 0 then   ptswin       = delstr(line,1,16)
  98.       if pos(points_drw,line) > 0 then   ptsdrw       = delstr(line,1,16)
  99.       if pos(points_lse,line) > 0 then   ptslse       = delstr(line,1,16)
  100.       if pos(points_gls,line) > 0 then   ptsgls       = delstr(line,1,16)
  101.       if pos(releg,line) > 0 then        lreg         = delstr(line,1,12)
  102.       if pos(playother,line) > 0 then    lplayo       = delstr(line,1,12)
  103.       if pos(promoted,line) > 0 then     promo        = delstr(line,1,10)
  104.       if pos(num_divs,line) > 0 then     ndivs        = delstr(line,1,15)
  105.       if pos(divisions,line) > 0 then    divs         = delstr(line,1,11)
  106.       if pos(separator,line) = 0 then do
  107.          line = strip(line)
  108.          tcount         = tcount + 1
  109.          teams.tcount   = line
  110.          records.tcount = 0
  111.          undefeat.tcount= ''
  112.          mats.tcount    = 0
  113.          pct.tcount     = 0
  114.       end
  115.    end
  116.    close(datafile)
  117. end
  118. else do
  119.    say
  120.    say "ERROR :    (LStats / League Information)"
  121.    say
  122.    say "Cannot open '"league_file||input_file"' for reading."
  123.    exit
  124. end
  125.  
  126. line_ct = 0
  127. matches = 0
  128. high_df = 0
  129. high_ht = ''
  130. high_at = ''
  131. high_hw = 0
  132. high_aw = 0
  133. high_hs = 0
  134. high_as = 0
  135. draws   = 0
  136. hwins   = 0
  137. awins   = 0
  138. type    = 0
  139. hcls    = 99
  140. acls    = 99
  141. nlines. = '???'
  142. nlcnt   = 0
  143. if open(datafile,league_file || input2_file,'r') then do
  144.    do while ~eof(datafile)
  145.       line_ct = line_ct + 1
  146.       line = readln(datafile)
  147.       if pos(separator,line) = 0 then do
  148.          if pos(not_played,line) = 0 then do
  149.             home_team = strip(substr(line,1,30))
  150.             goals_for = substr(line,32,2)
  151.             goals_aga = substr(line,37,2)
  152.             away_team = strip(substr(line,41,30))
  153.             call save_data(home_team,away_team,goals_for,goals_aga)
  154.  
  155.             if home_team ~= away_team & home_team ~= '' & away_team ~= '' then
  156.                matches   = matches + 1
  157.             diff = 0
  158.             if goals_for = goals_aga & home_team ~= away_team then do
  159.                draws = draws + 1
  160.                type = 0
  161.             end
  162.             if goals_for > goals_aga then do
  163.                hwins = hwins + 1
  164.                diff  = goals_for - goals_aga
  165.                type  = 1
  166.             end
  167.             if goals_for < goals_aga then do
  168.                awins = awins + 1
  169.                diff  = goals_aga - goals_for
  170.                type  = 2
  171.             end
  172.             if type = 1 then do
  173.                if diff >= high_hw then do
  174.                   nlcnt = nlcnt + 1
  175.                   nlines.nlcnt = line
  176.                   if ((goals_for > high_hs) | (diff = goals_for)) | (diff = high_hw & goals_aga <= hcls) then do
  177.                      high_hw = diff
  178.                      hcls    = goals_aga
  179.                      high_hs = goals_for
  180.                      high_ht = line
  181.                   end
  182.                end
  183.             end
  184.             if type = 2 then do
  185.                if diff >= high_aw then do
  186.                   nlcnt = nlcnt + 1
  187.                   nlines.nlcnt = line
  188.                   if ((goals_aga > high_as) | (diff = goals_aga)) | (diff = high_aw & goals_for <= acls) then do
  189.                      high_as = goals_aga
  190.                      high_at = line
  191.                      high_aw = diff
  192.                      acls    = goals_for
  193.                   end
  194.                end
  195.             end
  196.             type = 0
  197.          end
  198.       end
  199.    end
  200.    close(datafile)
  201.  
  202.    r  = 0
  203.    rc = 0
  204.    u  = 1
  205.    uc = 0
  206.    do i=1 to tcount
  207.       pct.i = trunc((records.i/(mats.i*ptswin) * 100),1)
  208.       if pct.i > r then r = pct.i
  209.    end
  210.    do i=1 to tcount
  211.       if pct.i = r then do
  212.          rc = rc + 1
  213.          rstring.rc = teams.i || " with " || records.i || "pts from " || mats.i || " matches. ( " || pct.i || "% )"
  214.       end
  215.    end
  216.  
  217.    do i=1 to tcount
  218.       if length(undefeat.i) > u then
  219.          u  = length(undefeat.i)
  220.    end
  221.  
  222.    do i=1 to tcount
  223.       if length(undefeat.i) = u then do
  224.          uc = uc + 1
  225.          undefeat.i=strip(undefeat.i)
  226.          ucn = (length(undefeat.i) * 2) - 1
  227.          call format_perf(undefeat.i,ucn)
  228.          if ucn = 1 then ptemp = undefeat.i
  229.          if length(ptemp) > 0 then
  230.             ustring.uc = "           " || left(teams.i,30) || " (" || ptemp || ")"
  231.       end
  232.    end
  233.  
  234.    hmw   = trunc((hwins/matches) * 100,1)
  235.    dm    = trunc((draws/matches) * 100,1)
  236.    amw   = trunc((awins/matches) * 100,1)
  237.    hwins = centre(hwins,5)
  238.    draws = centre(draws,5)
  239.    awins = centre(awins,5)
  240.  
  241.    say
  242.    say center("League Information for '"league_title"'",78)
  243.    say "-------------------------------------------------------------------------------"
  244.    say
  245.    say "                                               Author : "author
  246.    say "                                               Created: "ddate
  247.    say "                                               Version: "lversion
  248.    say
  249.    say "Matches played : "matches
  250.    say
  251.    say "Home Wins      : "hwins"  ( "hmw"% )"
  252.    say "Draws          : "draws"  ( "dm"% )"
  253.    say "Away Wins      : "awins"  ( "amw"% )"
  254.    say
  255.    say "Points For Win  : "ptswin
  256.    say "Points For Draw : "ptsdrw
  257.    say "Points For Loss : "ptslse
  258.    say "Points Per Goal : "ptsgls"    (NOT used for Best Record/Undefeated Run)"
  259.    say
  260.    say "Number of Teams Promoted   : "promo
  261.    say "Number of Teams Relegated  : "lreg
  262.    say "Play Each Team             : "lplayo
  263.    say
  264.    say "Number of Related Divisions: "ndivs - 1
  265.    say "Related Divisions          : "divs
  266.    say "_______________________________________________________________________________"
  267.    say
  268.    say "Biggest Home Win       (Priority given to teams with less goals scored against)"
  269.    say "----------------"
  270.    say
  271.    hline = substr(high_ht,32,2)"   "substr(high_ht,37,2)
  272.    if hline ~= "" then do
  273.       do i=1 to nlcnt
  274.          if pos(hline,nlines.i) > 0 then
  275.             say nlines.i
  276.       end
  277.    end
  278.    else
  279.       say "None found."
  280.    say
  281.    say "Biggest Away Win"
  282.    say "----------------"
  283.    say
  284.    aline = substr(high_at,32,2)"   "substr(high_at,37,2)
  285.    if aline ~= "" then do
  286.       do i=1 to nlcnt
  287.          if pos(aline,nlines.i) > 0 then
  288.             say nlines.i
  289.       end
  290.    end
  291.    else
  292.       say "None found."
  293.    say "_______________________________________________________________________________"
  294.    say
  295.    say "Best Record"
  296.    say "-----------"
  297.    say
  298.    do i=1 to rc
  299.       say rstring.i
  300.    end
  301.    say
  302.    say
  303.    say "Current Best Undefeated Run"
  304.    say "---------------------------"
  305.    say
  306.    ustring.1 = overlay(u || " games :",ustring.1,1)
  307.    do i=1 to uc
  308.       say ustring.i
  309.    end
  310.    say
  311.    say "-------------------------------------------------------------------------------"
  312. end
  313. else do
  314.    say
  315.    say "ERROR :    (LStats / League Information)"
  316.    say
  317.    say "Cannot open '"league_file||input2_file"' for reading."
  318.    exit
  319. end
  320.  
  321. exit
  322.  
  323. /* Routine ---------------------------------------------------------- */
  324.  
  325. save_data:
  326. PARSE ARG homet,awayt,gf,ga
  327.  
  328. h = 0
  329. a = 0
  330. do i=1 to tcount
  331.    if pos(strip(homet),teams.i) > 0 then do
  332.       h = i
  333.       mats.i = mats.i + 1
  334.    end
  335.    if pos(strip(awayt),teams.i) > 0 then do
  336.       mats.i = mats.i + 1
  337.       a = i
  338.    end
  339. end
  340. if a = 0 | h = 0 then return
  341.  
  342. if gf > ga then do
  343.    records.h = records.h + ptswin
  344.    records.a = records.a + ptslse
  345.    undefeat.h = insert('W',undefeat.h,length(undefeat.h),1)
  346.    undefeat.a = ''
  347. end
  348. if gf < ga then do
  349.    records.a = records.a + ptswin
  350.    records.h = records.h + ptslse
  351.    undefeat.a = insert('W',undefeat.a,length(undefeat.a),1)
  352.    undefeat.h = ''
  353. end
  354. if gf = ga then do
  355.    records.a = records.a + ptsdrw
  356.    records.h = records.h + ptsdrw
  357.    undefeat.a = insert('D',undefeat.a,length(undefeat.a),1)
  358.    undefeat.h = insert('D',undefeat.h,length(undefeat.h),1)
  359. end
  360. /*
  361. records.a = records.a + (ga * ptsgls)    PTS_PER_GLS - NOT USED FOR PERFORMANCE...
  362. records.h = records.h + (gf * ptsgls)
  363. */
  364. return
  365.  
  366. /* Routine ---------------------------------------------------------- */
  367.  
  368. format_perf:
  369. ARG fstrg,counter
  370.  
  371. ptemp = ''
  372. ii = 1
  373. jj = 1
  374. do while ii <= counter
  375.    ptemp = insert(substr(fstrg,jj,1),ptemp,ii,1)
  376.    ii = ii + 1
  377.    jj = jj + 1
  378.    if ii < counter then do
  379.       ptemp = insert(".",ptemp,ii,1)
  380.       ii = ii + 1
  381.    end
  382. end
  383. ptemp = strip(ptemp)
  384. return
  385.  
  386. /* ------------------------------------------------------------------ */